<template>
  <!-- 资讯 -->
  <div class="information-form">
    <el-form :model="formData">
      <el-form-item label="列表样式">
        <el-radio-group v-model="formData.showStyle">
          <el-radio v-for="item in showStyles"
                    :key="item.value"
                    :label="item.value">{{item.label}}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="添加资讯">最多可添加10个，最少可添加4个</el-form-item>
    </el-form>

    <div class="information-form-list"
         v-for="(item,index) in formData.informationList"
         :key="index">
      <div class="information-form-list__item">
        <span class="information-form-list__title">文章标题：</span>
        <span class="information-form-list__content">{{item.title}}</span>
      </div>
      <i @click="handleRemove(index)"
         class="information-form-list__remove el-icon-error"></i>
    </div>

    <el-row v-if="this.formData.informationList.length < 10"
            type="flex"
            align="middle"
            justify="space-between">
      <el-button @click="handelAddInformation">添加资讯</el-button>
      <div>上下拖动可排序</div>
    </el-row>
  </div>
</template>

<script lang="ts">
import { Vue, Component, Prop } from "vue-property-decorator";
import Information from "./Information";
import InformationInfo from "./InformationInfo";

interface Sytles {
  label: string;
  value: string;
}

@Component
export default class InformationForm extends Vue {
  @Prop()
  formData: Information;

  showStyles: Sytles[] = [
    {
      label: "大图模式",
      value: "is-style-one",
    },
    {
      label: "列表模式",
      value: "is-style-two",
    },
  ];

  /**
   * 添加资讯
   */
  handelAddInformation() {
    if (this.formData.informationList.length >= 10) {
      this.$message.warning("最多可添加10个");
      return;
    }
    const storeNavigationItem: InformationInfo = new InformationInfo();
    this.formData.informationList.push(storeNavigationItem);
  }

  /**
   * 移除资讯
   */
  handleRemove(index) {
    this.formData.informationList.splice(index, 1);
  }
}
</script>